using UniversalAdmin.Domain.Entities;

namespace UniversalAdmin.Application.Services
{
    /// <summary>
    /// 用户认证服务接口
    /// </summary>
    public interface IAuthService
    {
        /// <summary>
        /// 验证用户凭据
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>验证成功的用户，失败返回null</returns>
        Task<User?> ValidateUserAsync(string username, string password);

        /// <summary>
        /// 获取用户角色
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns>用户角色列表</returns>
        Task<IEnumerable<string>> GetUserRolesAsync(int userId);

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="usernameOrEmail">用户名或邮箱</param>
        /// <param name="password">密码</param>
        /// <returns>登录结果</returns>
        Task<LoginResult> LoginAsync(string usernameOrEmail, string password);

        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="email">邮箱</param>
        /// <param name="password">密码</param>
        /// <returns>注册结果</returns>
        Task<LoginResult> RegisterAsync(string username, string email, string password);

        /// <summary>
        /// 刷新访问令牌
        /// </summary>
        /// <param name="refreshToken">刷新令牌</param>
        /// <returns>刷新结果</returns>
        Task<RefreshTokenResult> RefreshTokenAsync(string refreshToken);
    }

    /// <summary>
    /// 登录结果
    /// </summary>
    public class LoginResult
    {
        public bool Success { get; set; }
        public string? AccessToken { get; set; }
        public string? RefreshToken { get; set; }
        public int ExpiresIn { get; set; }
        public UserInfo? User { get; set; }
        public string? ErrorMessage { get; set; }
    }

    /// <summary>
    /// 用户信息
    /// </summary>
    public class UserInfo
    {
        public int Id { get; set; }
        public string Username { get; set; } = string.Empty;
        public string Email { get; set; } = string.Empty;
        public IEnumerable<string> Roles { get; set; } = Array.Empty<string>();
    }

    /// <summary>
    /// 刷新令牌结果
    /// </summary>
    public class RefreshTokenResult
    {
        public bool Success { get; set; }
        public string? AccessToken { get; set; }
        public string? RefreshToken { get; set; }
        public int ExpiresIn { get; set; }
        public string? ErrorMessage { get; set; }
    }
}
